﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BattleThis.Mvc
{
	/// <summary>
	/// Attribute make sure a player is in a current game.
	/// </summary>
	public class IsInGameAttribute : ActionFilterAttribute
	{
		/// <summary>
		/// Called by the ASP.NET MVC framework before the action method executes.
		/// </summary>
		/// <param name="filterContext">The filter context.</param>
		public override void OnActionExecuting( ActionExecutingContext filterContext )
		{
			if( !filterContext.HttpContext.HasGameContext() )
				filterContext.Result =new RedirectToRouteResult( 
					new System.Web.Routing.RouteValueDictionary( new {action = "LogOn", controller = "Account"}) );

			base.OnActionExecuting( filterContext );
		}
	}
}